package com.fjnldx.mes.mapper.Quota;

import com.fjnldx.mes.domain.pojo.MesDinger;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface QuotaMapper {

    /*
     * 新增定额
     */
    @Insert("insert into mes_dinger(gongxu,pz,ds,dl,xiaolv,cs,zl,tc,jisuan) " +
            "values(#{gongxu},#{pz},#{ds},#{dl},#{xiaolv},#{cs},#{zl},#{tc},#{jisuan})")
    int insertQuota(MesDinger data);

    /**
     * 定额查询
     */
    @Select("<script>" +
            " SELECT * FROM mes_dinger " +
            " WHERE 1=1" +
            "<if test='id!=null'> AND id=#{id} </if>" +
            "<if test=\"gongxu!=null and gongxu !=''\">AND gongxu=#{gongxu} </if>" +
            "<if test=\"pz!=null and pz!=''\"> AND pz=#{pz} </if>" +
            "<if test='ds!=null'> AND ds=#{ds} </if>" +
            "<if test='dl!=null'> AND dl=#{dl} </if>" +
            "<if test='xiaolv!=null'> AND xiaolv=#{xiaolv} </if>" +
            "<if test='cs!=null'> AND cs=#{cs} </if>" +
            "<if test='zl!=null'> AND zl=#{zl} </if>" +
            "<if test='tc!=null'> AND tc=#{tc} </if>" +
            "<if test='jisuan!=null'> AND jisuan=#{jisuan} </if>" +
            "<if test='size!=-1'> limit ${page*size},#{size} </if>" +
            "</script>")
    List<MesDinger> queryQuota(MesDinger data);

    /**
     * 获取当前定额total
     * @return
     */
    @Select("<script>" +
            "SELECT count(*) FROM ( " +
            " SELECT * FROM mes_dinger " +
            " WHERE 1=1" +
            "<if test='id!=null'> AND id=#{id} </if>" +
            "<if test=\"gongxu!=null and gongxu !=''\">AND gongxu=#{gongxu} </if>" +
            "<if test=\"pz!=null and pz!=''\"> AND pz=#{pz} </if>" +
            "<if test='ds!=null'> AND ds=#{ds} </if>" +
            "<if test='dl!=null'> AND dl=#{dl} </if>" +
            "<if test='xiaolv!=null'> AND xiaolv=#{xiaolv} </if>" +
            "<if test='cs!=null'> AND cs=#{cs} </if>" +
            "<if test='zl!=null'> AND zl=#{zl} </if>" +
            "<if test='tc!=null'> AND tc=#{tc} </if>" +
            "<if test='jisuan!=null'> AND jisuan=#{jisuan} </if>" +
            ") a " +
            "</script>")
    int queryTotalQuota(MesDinger data);

    /**
     * 删除定额
     */
    @Delete("<script>" +
            "DELETE FROM mes_dinger WHERE id In" +
            "<foreach collection='array' item='item' index='index' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    int deleteQuota(String[] array);

    /**
     * 更新定额
     */
    @Update("<script>" +
            "update mes_dinger " +
            "<trim prefix='set' suffixOverrides=','> " +
            "<if test='gongxu!=null'> gongxu=#{gongxu}, </if>" +
            "<if test='pz!=null'> pz=#{pz}, </if>" +
            "<if test='ds !=null'> ds=#{ds}, </if>" +
            "<if test='dl !=null'> dl=#{dl}, </if>" +
            "<if test='xiaolv!=null'>  xiaolv=#{xiaolv}, </if>" +
            "<if test='cs!=null'> cs=#{cs}, </if>" +
            "<if test='zl!=null'> zl=#{zl}, </if>" +
            "<if test='tc!=null'> tc=#{tc}, </if>" +
            "<if test='jisuan!=null'> jisuan=#{jisuan}, </if>" +
            "</trim> " +
            " WHERE id=#{id}" +
            "</script>")
    int updateQuota(MesDinger data);
}
